package admin

import (
	"news_for_deepseek_interface/controller"
	"news_for_deepseek_interface/dto"
	adminDto "news_for_deepseek_interface/dto/admin"
	adminService "news_for_deepseek_interface/service/admin"

	"github.com/gin-gonic/gin"
)

func RefreshToken(c *gin.Context) {
	//1. 参数绑定
	var params adminDto.RefreshTokenRequest
	if err := c.ShouldBindJSON(&params); err != nil {
		controller.Fail(c, controller.ParamsError, err.Error())
		return
	}

	//2. 验证参数
	if err := dto.Validate(params); err != nil {
		controller.Fail(c, controller.ParamsError, err.Error())
		return
	}

	//3. 调用服务层处理登录逻辑
	response, err := adminService.RefreshToken(params)
	if err != nil {
		controller.Fail(c, controller.BusinessError, err.Error())
		return
	}

	//4. 返回成功响应
	controller.Success(c, response)
}
